package com.xuhnagchen.automation.util;

import com.google.gson.Gson;
import com.xuhnagchen.automation.entity.Result;

public class ResultUtil<T> {
    private transient Gson gson = new Gson();
    //private String requestTime;
    private int code;
    private T data;
    private String msg;


    public ResultUtil(Result<T> data1) {
        this.code = data1.getCode();
        this.data = data1.getData();
        this.msg = data1.getMsg();
    }

    public ResultUtil(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
    }


    public String toJson() {
        String jsonValue = gson.toJson(this);
        System.out.println("jsonValue1 = "+ jsonValue);
        return jsonValue;
    }

    public static String getReturn(int code, String msg) {
        ResultUtil util = new ResultUtil(code, msg);
        return util.toJson();
    }

    public static String getReturn(Result<?> result) {
        ResultUtil util = new ResultUtil(result);
        return util.toJson();
    }
}
